package com.example.cuilei.contentprovider;

import android.app.Activity;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

/**
 * Created by Lay on 2014/12/9.
 */
public class MyContentResolverActivity extends Activity {
    private Uri uri;
    private ContentResolver resolver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_resolver);
        uri = Uri.parse("content://www.lalio.xyz.content/");
        resolver = getContentResolver();
    }

    public void insert(View view) {
        ContentValues vs = new ContentValues();
        vs.put("name", "小明");
        Uri newUri = resolver.insert(uri, vs);
        Toast.makeText(this, "insert的返回值为：" + newUri, Toast.LENGTH_SHORT).show();
    }

    public void delete(View view) {
        int count = resolver.delete(uri, "delete_where", null);
        Toast.makeText(this, "delete的记录条数是：" + count, Toast.LENGTH_SHORT).show();

    }

    public void update(View view) {
        ContentValues vs = new ContentValues();
        vs.put("name", "草泥马");
        int count = resolver.update(uri, vs, "update_where", null);
        Toast.makeText(this, "update的记录条数是：" + count, Toast.LENGTH_SHORT).show();

    }

    public void query(View view) {
        Cursor cursor = resolver.query(uri, null, "query_where", null, null);
        Toast.makeText(this, "query的返回结果是：" + cursor, Toast.LENGTH_SHORT).show();

    }
}
